<?php

namespace App\Pool;


use Swoole\Coroutine;
use Swoole\Coroutine\Channel;
use Swoole\Runtime;

class Db
{
    /**
     * 获取驱动
     */
    public static function getDriver()
    {
        return app('mysql_pool');
    }

    /**
     * @param $name
     * @param $arguments
     * @return mixed
     */
    public static function __callStatic($name, $arguments)
    {
        // 开启一键协程化
        Runtime::enableCoroutine();
        // 实例化通道，用于协程间通讯
        $channel = new Channel(1);
        Coroutine::create(function () use ($channel, $name, $arguments) {
            $pdo    = self::getDriver();
            $return = $pdo->$name(...$arguments);
            $channel->push($return);
        });

        return $channel->pop();
    }
}